<template>
  <div class="container">
    <div class="app-container" />
    <el-input v-model="pageParams.name" placeholder="请输入企业名称" style="width: 300px; margin-bottom: 20px;" @input="changeValue" />
    <el-button type="primary" @click="search">查询</el-button>
    <el-row>
      <el-button style="margin-bottom: 20px;" @click="addEnterprise">添加企业</el-button>
    </el-row>
    <el-table :data="list" style="width: 100%">
      <el-table-column type="expand">
        <template>
          <el-table>
            <el-table-column align="center" label="租赁楼宇" />
            <el-table-column align="center" label="租赁起止时间" />
            <el-table-column align="center" label="合同状态" />
            <el-table-column align="center" label="操作">
              <template>
                <el-button type="text">查看</el-button>
                <el-button type="text">编辑</el-button>
                <el-button type="text">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </el-table-column>
      <el-table-column type="index" label="序号" width="180" align="center" />
      <el-table-column prop="name" label="企业名称" width="180" align="center" />
      <el-table-column prop="contact" label="联系人" width="180" align="center" />
      <el-table-column prop="contactNumber" label="联系电话" width="180" align="center" />
      <el-table-column label="操作" align="center">
        <template>
          <el-button size="mini">添加合同</el-button>
          <el-button size="mini">查看</el-button>
          <el-button size="mini">编辑</el-button>
          <el-button size="mini" type="danger">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-row type="flex" justify="end">
      <el-pagination
        :current-page="pageParams.page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageParams.pageSize"
        layout="total, sizes, prev, pager,jumper, next"
        :total="pageParams.total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-row>
  </div>
</template>
<script>
import { getEnterPriesAPI } from '@/api'

export default {
  name: 'EnterPries',
  data() {
    return {
      list: [],
      pageParams: {
        name: '',
        page: 1,
        pageSize: 10,
        total: 0
      }
    }
  },
  created() {
    this.getEnterprises()
  },
  methods: {
    async getEnterprises() {
      const { rows, total } = await getEnterPriesAPI(this.pageParams)
      this.list = rows
      this.pageParams.total = total
    },
    changeValue() {
      this.pageParams.page = 1
      clearTimeout(this.timer)
      this.timer = setTimeout(() => {
        this.getEnterprises()
      }, 500)
    }
  }
}
</script>
